<script>
	export default {
		globalData: {
			apiHost: 'https://www.wangkylin.top/device',
			version: '1.0.0'
		},
		onLaunch: function() {
			console.log('App Launch')
			// 初始化localstorage存储
			this.initLocalStorage();
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods: {
			initLocalStorage() {
				const systemInfo = uni.getSystemInfoSync()
				let systemLocale = systemInfo.osLanguage
				console.log('systemLocale', systemLocale)
				
				// 规范化语言代码
				if (systemLocale.startsWith('zh')) {
					systemLocale = 'zh-Hans'
				} else {
					systemLocale = 'en'
				}
				
				if (!uni.getStorageSync('currentLanguage')) {
					uni.setStorage({
						key:'currentLanguage',
						data: systemLocale
					})
				}
				
				// 同步设置当前语言
				uni.setLocale(systemLocale)
			}
		}
	}
</script>

<style>
	/*每个页面公共css */
</style>
